package com.foxire.controller;

import com.foxire.Pojo.Address;
import com.foxire.Pojo.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class ResponseController {
//    @RequestMapping("/helloRes")
//    public String hello() {
//        System.out.println("Hello World!_Res");
//        return "Hello World!";
//    }
//
//    @RequestMapping("/getAddr")
//    public Address getAddr() {
//        System.out.println("getAddr");
//        Address addr = new Address();
//        addr.setCity("重庆");
//        addr.setProvince("重庆");
//        return addr;
//    }
//
//    @RequestMapping("/listAddr")
//    public List<Address> listAddr() {
//        System.out.println("listAddr");
//        List<Address> list = new ArrayList<>();
//
//        Address addr1 = new Address();
//        addr1.setCity("重庆1");
//        addr1.setProvince("重庆1");
//        list.add(addr1);
//        Address addr2 = new Address();
//        addr2.setCity("上海");
//        addr2.setProvince("上海");
//        list.add(addr2);
//        return list;
//    }

    // 封装返回结果
    @RequestMapping("/helloRes")
    public Result hello() {
        System.out.println("Hello World!_Res");
//        return new Result(1, "success", "Hello World!");
        return Result.success("Hello World!");
    }

    @RequestMapping("/getAddr")
    public Result getAddr() {
        System.out.println("getAddr");
        Address addr = new Address();
        addr.setCity("重庆");
        addr.setProvince("重庆");
        return Result.success(addr);
    }

    @RequestMapping("/listAddr")
    public Result listAddr() {
        System.out.println("listAddr");
        List<Address> list = new ArrayList<>();

        Address addr1 = new Address();
        addr1.setCity("重庆1");
        addr1.setProvince("重庆1");
        list.add(addr1);
        Address addr2 = new Address();
        addr2.setCity("上海");
        addr2.setProvince("上海");
        list.add(addr2);
        return Result.success(list);
    }
}
